<template>
	<view class="">
		<view class="form-body">
			<u--form :model="formData" ref="mForm" labelWidth="180" errorType="toast" >
				<u-form-item label="方案名称" prop="schemeName" borderBottom required>
					<u-input v-model="formData.schemeName" border="none" placeholder="请输入" inputAlign="right" disabledColor="#fff"/>
				</u-form-item>
				<u-form-item label="入股金额" prop="amount" borderBottom required>
					<u-input v-model="formData.amount" border="none" type="digit" placeholder="请输入" inputAlign="right" disabledColor="#fff"/>
					<text slot="right">元</text>
				</u-form-item>
				<u-form-item label="客户消费分红" prop="bonusConsume" borderBottom required>
					<u-input v-model="formData.bonusConsume" type="digit" border="none" placeholder="请输入" inputAlign="right" disabledColor="#fff"/>
					<text slot="right">%</text>
				</u-form-item>
				<u-form-item label="联创分销分红比例" prop="bonusDistributionProfit " borderBottom required>
					<u-input v-model="formData.bonusDistributionProfit " type="digit" border="none" placeholder="请输入" inputAlign="right" disabledColor="#fff"/>
					<text slot="right">%</text>
				</u-form-item>
				<u-form-item label="联创管家分红比例" prop="bonusManagerProfit" borderBottom required>
					<u-input v-model="formData.bonusManagerProfit" type="digit" border="none" placeholder="请输入" inputAlign="right" disabledColor="#fff"/>
					<text slot="right">%</text>
				</u-form-item>
				<u-form-item label="联创管家年度分红比例" prop="bonusYearManagerProfit" borderBottom required>
					<u-input v-model="formData.bonusYearManagerProfit" type="digit" border="none" placeholder="请输入" inputAlign="right" disabledColor="#fff"/>
					<text slot="right">%</text>
				</u-form-item>
				<u-form-item label="联创推荐联创之现金奖励" prop="cashbackSuggestProfit" borderBottom required>
					<u-input v-model="formData.cashbackSuggestProfit" type="digit" border="none" placeholder="请输入" inputAlign="right" disabledColor="#fff"/>
					<text slot="right">%</text>
				</u-form-item>
				<u-form-item label=" 限制股本消费最低值" prop="lowestBonusLimit" borderBottom required>
					<u-input v-model="formData.lowestBonusLimit" type="digit" border="none" placeholder="请输入" inputAlign="right"  disabledColor="#fff"/>
					<text slot="right">%</text>
				</u-form-item>
				<u-form-item label="产品利润分红" prop="bonusGoodsProfit" borderBottom required>
					<u-input v-model="formData.bonusGoodsProfit" type="digit" border="none" placeholder="请输入" inputAlign="right"  disabledColor="#fff"/>
					<text slot="right">%</text>
				</u-form-item>
				<u-form-item label="股本消费" prop="rechargeBalance" borderBottom>
					<view class="flex justify-between">
						<view></view>
						<u-switch v-model="formData.rechargeBalance" />
					</view>
				</u-form-item>
				<u-form-item label="股本可退" prop="refundable">
					<view class="flex justify-between">
						<view></view>
						<u-switch v-model="formData.refundable" />
					</view>
				</u-form-item>
			</u--form>
		</view>
		<view class="mt-100 pl-40 pr-40">
			<view class="">
				<u-button type="primary" color="#e54d42" text="提交" @click="submit" size="large" />
			</view>
			<view class="mt-20" v-if="isEdit">
				<u-button type="primary" color="#e54d42" plain text="删除" @click="onDel" size="large" />
			</view>
		</view>
		<u-toast ref="uToast"></u-toast>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				isEdit: false,
				formData: {
					id:0,
					schemeName: '',
					bonusType: 0,
					amount: '',
					bonusConsume: '',
					bonusGoodsProfit: '',
					rechargeBalance:false,
					bonusDistributionProfit: '',
					cashbackSuggestProfit:'',
					lowestBonusLimit:'',
					bonusManagerProfit: '',
					bonusYearManagerProfit: '',
					refundable:false,
					itemType: 0,
				},
				rules: {
					schemeName:[{
						type:'string',
						required: true, 
						message: '请输入方案名称',
						trigger: ['change','blur'],
					}],
					amount:[{
						type:'number',
						required: true, 
						message: '请输入股金额',
						trigger: ['change','blur'],
					}],
					bonusConsume:[{
						type:'number',
						required: true, 
						message: '请输入客户消费分红',
						trigger: ['change','blur'],
					}],
					bonusGoodsProfit:[{
						type:'number',
						required: true, 
						message: '请输入产品利润分红',
						trigger: ['change','blur'],
					}],
					bonusDistributionProfit:[{
						type:'number',
						required: true, 
						message: '请输入联创分销分红比例',
						trigger: ['change','blur'],
					}],
					bonusManagerProfit:[{
						type:'number',
						required: true, 
						message: '请输入联创管家分红比例',
						trigger: ['change','blur'],
					}],
					bonusYearManagerProfit:[{
						type:'number',
						required: true, 
						message: '请输入联创推荐联创之现金奖励',
						trigger: ['change','blur'],
					}],
					cashbackSuggestProfit:[{
						type:'number',
						required: true, 
						message: '请输入',
						trigger: ['change','blur'],
					}],
					lowestBonusLimit:[{
						type:'number',
						required: true, 
						message: '请输入限制股本消费最低值',
						trigger: ['change','blur'],
					}],
				}
			}
		},
		onLoad(option) {
			let that = this
			if (option.id) {
				uni.setNavigationBarTitle({ title: '编辑分红方案', })
				this.isEdit = true
				this.getEdit(option.id)
			}else {
				uni.setNavigationBarTitle({ title: '添加分红方案', })
			}
		},
		onReady() {
			this.$refs.mForm.setRules(this.rules)
		},
		methods: {
			getEdit(id) {
				this.$reqJsonPost('GetBonusSchemeGetEdit', { id: id, itemType: 0 }).then(res => {
					this.formData = res.data
				})
			},
			submit() {
				this.$refs.mForm.validate().then(res=>{
					if (this.isEdit) {
						this.$reqJsonPost('BonusSchemeDoEdit',this.formData).then(data => {
							this.$refs.uToast.show({
								message: data.msg,
								complete(){
									uni.navigateBack()
								}
							})
						})
					}else {
						this.$reqJsonPost('BonusSchemeDoCreate', this.formData).then(data=>{
							this.$refs.uToast.show({
								message: data.msg,
								complete(){
									uni.navigateBack()
								}
							})
						})
					}
				})
			},
			onDel(){
				this.$reqJsonPost('BonusSchemeDoDelete',{ id:this.formData.id, itemType: 0 }).then(res=>{
					this.$refs.uToast.show({
						message: res.msg,
						complete(){
							uni.navigateBack()
							
						}
					})
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.form-body {
		padding: 20rpx 20rpx 0 20rpx;
		background-color: #fff;
	}

	.pro-box {
		.seims {
			font-size: 28rpx;
			padding: 20rpx;
			color: #999;
		}

		.pro-list {
			padding: 0 20rpx;
			margin-bottom: 8rpx;
			background-color: #fff;
			.delBtn {
				border: 1px #fa436a solid;
				color: #fa436a;
				font-size: 22rpx;
				padding: 0 20rpx;
				border-radius: 6rpx;
			}
		}
	}
	.marginTop60{ margin-top: 30rpx;}

</style>
